package cn.com.wms.controller;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.support.RequestContext;

@Controller
@RequestMapping("/demo")
public class DemoCtr {

	@RequestMapping("/tsta")
	public String tsta(HttpSession ss, Model model, HttpServletRequest req, HttpServletResponse res) {
		System.out.println(" ========================a====================== ");
		//设置国际化语言
		Locale loc = new Locale("en","US");
		
	    //基于cookie的国际化
	    (new CookieLocaleResolver()).setLocale (req, res, loc);
	    
	    //从后台代码获取国际化信息
	    RequestContext requestContext = new RequestContext(req);
	    System.out.println("en:"+requestContext.getMessage("login.username"));
	
		return "show";
	}
	
	@RequestMapping("/tstb")
	public String tstb(HttpSession ss, Model model, HttpServletRequest req, HttpServletResponse res) {
		System.out.println(" =======================b======================= ");
		
		//设置国际化语言
		Locale loc = new Locale("zh","CN");
		
	    //基于cookie的国际化
	    (new CookieLocaleResolver()).setLocale (req, res, loc);

	    //从后台代码获取国际化信息
	    RequestContext requestContext = new RequestContext(req);
        System.out.println("zh:"+requestContext.getMessage("login.username"));
		
		return "show";
	}

}
